home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / RCS_56.ARJ / MERGE.C < prev    next >
C/C++ Source or Header  |  1992-02-11  |  2KB  |  98 lines

  1. /* merge - three-way file merge */
  2.  
  3. /* Copyright 1991 by Paul Eggert
  4.    Distributed under license by the Free Software Foundation, Inc.
  5.  
  6. This file is part of RCS.
  7.  
  8. RCS is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2, or (at your option)
  11. any later version.
  12.  
  13. RCS is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with RCS; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. Report problems and direct all questions to:
  23.  
  24.     rcs-bugs@cs.purdue.edu
  25.  
  26. */
  27.  
  28. #include "rcsbase.h"
  29.  
  30.  
  31. static char const usage[] =
  32.  "\nmerge: usage: merge [-p] [-q] [-L label1 [-L label3]] file1 file2 file3\n";
  33.  
  34.     static exiting void
  35. badoption(a)
  36.     char const *a;
  37. {
  38.     faterror("unknown option: %s%s", a-2, usage);
  39. }
  40.  
  41.  
  42. mainProg(mergeId, "merge", "$Id: merge.c,v 1.2 1991/08/19 03:13:55 eggert Exp $")
  43. {
  44.     register char const *a;
  45.     char const *label[2], *arg[3];
  46.     int labels, tostdout;
  47.  
  48.     labels = 0;
  49.     tostdout = false;
  50.  
  51.     while ((a = *++argv)  &&  *a++ == '-') {
  52.         switch (*a++) {
  53.             case 'p': tostdout = true; break;
  54.             case 'q': quietflag = true; break;
  55.             case 'L':
  56.                 if (1<labels)
  57.                     faterror("too many -L options");
  58.                 if (!(label[labels++] = *++argv))
  59.                     faterror("-L needs following argument");
  60.                 --argc;
  61.                 break;
  62.             default:
  63.                 badoption(a);
  64.         }
  65.         if (*a)
  66.             badoption(a);
  67.         --argc;
  68.     }
  69.  
  70.     if (argc != 4)
  71.         faterror("%s arguments%s",
  72.             argc<4 ? "not enough" : "too many",  usage
  73.         );
  74.  
  75.     /* This copy keeps us `const'-clean.  */
  76.     arg[0] = argv[0];
  77.     arg[1] = argv[1];
  78.     arg[2] = argv[2];
  79.  
  80.     switch (labels) {
  81.         case 0: label[0] = arg[0]; /* fall into */
  82.         case 1: label[1] = arg[2];
  83.     }
  84.  
  85.     exitmain(merge(tostdout, label, arg));
  86. }
  87.  
  88.  
  89. #if lint
  90. #    define exiterr mergeExit
  91. #endif
  92.     exiting void
  93. exiterr()
  94. {
  95.     tempunlink();
  96.     _exit(DIFF_TROUBLE);
  97. }
  98.